﻿#pragma once

#include "ChatWindow.h"
#include "Client.h"
#include "UserListView.h"

typedef CMap<CString, LPCTSTR, ChatWindow*, ChatWindow*> Chats;

// 主窗口
class MainWindow: public CDialog {
    DECLARE_MESSAGE_MAP()

    private: Chats mChats;                  // 聊天窗口集合
    private: Client* mClient;               // 客户端
    private: UserListView mListViewUsers;   // 好友列表控件
    private: CStatusBarCtrl mStatusBar;     // 状态栏
    private: CToolBar mToolBar;             // 工具栏

    public: MainWindow(CWnd* parent = NULL);
    public: ~MainWindow();
    private: void AddAllFriends(LogonResult*);
    private: void AddOneFriend(LPCTSTR, int, BOOL isOnline = TRUE);
    private: void ChangeState(BOOL);
    private: void ClearChatWindow();
    private: ChatWindow* GetChatWindow(LPCTSTR);
    private: void GetResultMessage(ResultCode, CString*);
    private: void OnButtonAddFriendClicked();
    private: void OnButtonLogoffClicked();
    private: void OnButtonLogonClicked();
    private: void OnButtonMChatClicked();
    private: void OnButtonRegClicked();
    private: LRESULT OnChatC2S(WPARAM, LPARAM);
    private: LRESULT OnChatS2C(WPARAM, LPARAM);
    private: LRESULT OnFriendLogoff(WPARAM, LPARAM);
    private: LRESULT OnFriendLogon(WPARAM, LPARAM);
    private: LRESULT OnGetAddFriendRequest(WPARAM, LPARAM);
    private: LRESULT OnGetAddFriendResult(WPARAM, LPARAM);
    private: LRESULT OnGetLogonResult(WPARAM, LPARAM);
    private: LRESULT OnGetRegResult(WPARAM, LPARAM);
    private: virtual BOOL OnInitDialog();
    private: void OnListFriendsDoubleClicked(NMHDR*, LRESULT*);
};
